<template>
  <el-card>
    <div slot="header"><span>订单管理</span></div>
    <!-- 表单 -->
    <el-form inline :model="formData">
      <el-form-item label="订单号">
        <el-input v-model="formData.orderNo"> </el-input>
      </el-form-item>
      <el-form-item label="收货人">
        <el-input v-model="formData.consignee"> </el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="formData.phone"> </el-input>
      </el-form-item>
      <el-form-item label="订单状态">
        <el-select v-model="formData.orderState">
          <el-option value="已受理" label="已受理"></el-option>
          <el-option value="派送中" label="派送中"></el-option>
          <el-option value="已完成" label="已完成"></el-option>
        </el-select>
      </el-form-item>
      <!-- 选择时间 -->
      <el-form-item label="选择时间">
        <el-date-picker
          v-model="formData.date"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <!-- 查询 -->
      <el-button @click="search" class="ebpri" type="primary">查询</el-button>
    </el-form>

    <!-- 表格 -->
    <!-- id	订单id
orderNo	订单号
orderTime	下单时间
phone	联系电话
consignee	收货人
deliverAddress	送货地址
deliveryTime	送达时间
remarks	备注
orderAmount	订单金额
orderState	订单状态 -->
    <el-table :data="tableData" border :style="{ width: w + 'px' }">
      <el-table-column fixed label="订单号" prop="orderNo"></el-table-column>
      <el-table-column label="订单时间" prop="orderTime"></el-table-column>
      <el-table-column label="手机号" prop="phone"></el-table-column>
      <el-table-column label="收货人" prop="consignee"></el-table-column>
      <el-table-column label="配送地址" prop="deliverAddress"></el-table-column>
      <el-table-column label="送达时间" prop="deliveryTime"></el-table-column>
      <el-table-column label="备注" prop="remarks"></el-table-column>
      <el-table-column label="订单金额" prop="orderAmount"></el-table-column>
      <el-table-column label="订单状态" prop="orderState"></el-table-column>
      <!-- 操作 -->
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >查看</el-button
          >
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="nation-box">
      <el-pagination
        background=""
        class="nation"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[3, 5]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import { getOrderListReq } from "@/api/order";
// 引入mixins
import order from '@/mixins/order'
export default {
    mixins:[order],
  data() {
    return {
      formData: {
        orderNo: "", //订单号
        consignee: "", // 收货人
        phone: "", //  手机号
        orderState: "", //状态
        date: [], //日期
      },
      // 查询表单数据，用于解绑数据
      searchForm:{},

      //选择日期
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      value2: "",
      //   表格
      tableData: [],
      currentPage: 1,
      pageSize: 5,
      total: 0,
      w: 0, //table宽度
    };
  },
  methods: {
    // 查看功能
    handleClick(){
            console.log('查看');
    },
    async getData() {
      let currentPage = this.currentPage;
      let pageSize = this.pageSize;
      // 发请求
      let res = await getOrderListReq({
        currentPage,
        pageSize,
        ...  this.searchForm    //解构表单数据，让表单数据进来。
        
      });
      // 解构数据
      let { total, data } = res.data;
      // 数据赋值
      this.total = total;
      this.tableData = data;
    },

    // 查询功能
    search(){
      this.currentPage=1
      // 将formData的值浅拷贝赋值给查询表单使用
      this.searchForm={...this.formData}
    this.getData()
    },

    // 页码
    handleSizeChange(val) {
      // 1 获取当前每页 条数
      this.pageSize = val;
      // 2 拉去数据
      this.getData();
    },

    handleCurrentChange(val) {
      // 1 获取当前页面 赋值
      this.currentPage = val;
      // 2 发请求
      this.getData();
    },
    
  },

  //   初始化发请求
  created() {
    this.getData();
  },

};
</script>

<style lang="scss" scoped>
.ebpri {
  margin-left: 20px;
}
</style>